<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
	<link rel="stylesheet" href="../../../github/html/css/main.css" type="text/css" />
	<title>webshell</title>
</head>
<script LANGUAGE="JAVASCRIPT">
	function svc_connectPlatform() {
		//alert("");
		var wsServer = 'ws://127.0.0.1:4444/';
		try {
			svc_websocket = new WebSocket(wsServer);
		} catch (evt) {
			console.log("new WebSocket error:" + evt.data);
			svc_websocket = null;
			if (typeof(connCb) != "undefined" && connCb != null)
				connCb("-1", "connect error!");
			return;
		}
		//alert("");
		svc_websocket.onopen = svc_onOpen;
		svc_websocket.onclose = svc_onClose;
		svc_websocket.onmessage = svc_onMessage;
		svc_websocket.onerror = svc_onError;
	}
	function svc_onOpen(evt) {
		console.log("Connected to WebSocket server.");
	}
	function svc_onClose(evt) {
		console.log("Disconnected");
	}
	function svc_onMessage(evt) {
		console.log('Retrieved data from server: ' + evt.data);
		obj = JSON.parse(evt.data);
		var div = document.createElement("p");
		div.style = "white-space:pre-wrap";
		div.innerHTML = obj.data[0].value;
		document.getElementById(obj.data[0].id).appendChild(div);
		var tmp = document.getElementById("msg");
		tmp.scrollTop = tmp.scrollHeight;
	}
	function svc_onError(evt) {
		console.log('Error occured: ' + evt.data);
	}
	function svc_send() {
		if (svc_websocket.readyState == WebSocket.OPEN) {
			var buf = document.getElementById("buf");
			var msg = buf.value;
			console.log(msg);
			svc_websocket.send(msg);
			buf.value="";
		} else {
		console.log("send failed. websocket not open. please check.");
		}
	}

	function web(){
		var text = '{ "sites" : [' +
		    '{ "id":"514" , "value":"23" },' +
		    '{ "name":"Google" , "url":"www.google.com" },' +
		    '{ "name":"Taobao" , "url":"www.taobao.com" } ]}';

		obj = JSON.parse(text);
		document.getElementById(obj.sites[0].id).innerHTML = obj.sites[0].value;
	}
	function copyText(){
		var myselect=document.getElementById("select");
		console.log("fds");
	}
	function box_show(name){
		console.log(name);
		var myselect=document.getElementById(name);
		myselect.style.display="";
	}

</script>
<!--
	<textarea id="buf" class="text_show"  readonly="readonly" wrap='physical'>
	<textarea id="msg" class="text_show" readonly="readonly" wrap='physical'>
	</textarea>
	<div class="div_row" style="position:fixed; bottom:0;">
	<fieldset id="msg" class="text_show" style="positon:fixed;bottom:20vh;">
		<legend>shell</legend>
	</fieldset>
	<div id="msg" class="text_show" style="positon:fixed;bottom:20vh;">
	<div>
-->
<body>
<button onclick="svc_connectPlatform()"> connect</button><br>
<div class="div_column">
	<fieldset id="msg" class="text_show" style="positon:fixed;bottom:20vh; overflow:scroll">
		<legend>shell</legend>
	</fieldset>
	<div class="div_row" style="position:fixed;bottom:0;right:1vw;left:1vw">
		<input type="text" id="buf" name="firstname"  style="width:100vw" onkeydown="if(event.keyCode==13) {svc_send()}">
		<button id="send" onclick="svc_send()"> send</button><br>
	</div>
</div>
</body>

